class bb_std_lang:
	D2R=0.017453292519943295
	R2D=57.29577951308232

	errInfo = ""
	errStack = []

	@staticmethod
	def pushErr():
		bb_std_lang.errStack.append(bb_std_lang.errInfo)

	@staticmethod
	def popErr():
		bb_std_lang.errInfo = bb_std_lang.errStack.pop()

	@staticmethod
	def stackTrace():
		strg = ""
		bb_std_lang.pushErr()
		bb_std_lang.errStack.reverse()

		for e in bb_std_lang.errStack:
			strg += e+"\n"

		bb_std_lang.errStack.reverse()
		bb_std_lang.popErr()

		return strg

	@staticmethod
	def showError( err ):
		if err == "":
			return

		t = "Monkey runtime error: "+err+"\n"+bb_std_lang.stackTrace()

		print(t)

	@staticmethod
	def error( err ):
		raise err

	@staticmethod
	def stringArray( n ):
		return [""] * n

	@staticmethod
	def slice( strg, _from):
		return bb_std_lang.sliceFT(strg, _from, len(strg))

	@staticmethod
	def sliceFT( strg, _from, term):
		return strg[_from:term]


	@staticmethod
	def split( strg, sep ):
		return strg.split(sep)

	@staticmethod
	def fromChars( chars ):
		if type(chars) == list:
			return "".join(chars)
		else:
			return str(chr(chars))
		

	@staticmethod
	def sliceArray( arr, _from):
		return bb_std_lang.sliceArrayFT( arr, _from, len(arr) )

	@staticmethod
	def sliceArrayFT( arr, _from, term):
		return arr[_from:term]

	@staticmethod
	def stringCompare( lhs, rhs ):
		n=min( len(lhs),len(rhs) )
		for i in range(0, n):
			t = ord(lhs[i]) - ord(rhs[i])
			if t:
				return t
		return len(lhs) - len(rhs)
	
	@staticmethod
	def resizeArray(a, size):
		#print a
		if len(a) > 0:
			b = [a[0]]*size
			if size > len(a):
				b[0:len(a)] = a[0:len(a)]
				for i in range(len(a), size):
					if type(a[0]) == int:
						b[i] = 0
					elif type(a[0]) == float:
						b[i] = 0.0
					elif type(a[0]) == list:
						b[i] = 0.0
					elif type(a[0]) == str:
						b[i] = ""
					elif type(a[0]) == list:
						b[i] = []
					elif type(a[0]) == dict:
						b[i] = {}
					else:
						b[i] = 0
			else:
				b[0:size] = a[0:size]
			return b
		else:
			return [None]*size



